<?php

/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/

/**
* Smarty phone number format modifier plugin
*
* Type: modifier<br>
* Name: number_format<br>
* Purpose: format number via currency
* @param string
* @return string
*/

function smarty_modifier_phone_number_format($sPhone){
    $sPhone = ereg_replace("[^0-9]",'',$sPhone);
    if(strlen($sPhone) == 10){
	    $sArea = substr($sPhone,0,3);
	    $sPrefix = substr($sPhone,3,3);
	    $sNumber = substr($sPhone,6,4);
	    $sPhone = "(".$sArea.")".$sPrefix."-".$sNumber;
	    return($sPhone);
    }else if (strlen($sPhone) == 11){
    	$sPhone = substr($sPhone,1,10);
    	$sArea = substr($sPhone,0,3);
	    $sPrefix = substr($sPhone,3,3);
	    $sNumber = substr($sPhone,6,4);
	    $sPhone = "(".$sArea.")".$sPrefix."-".$sNumber;
	    return($sPhone);
	  }else if (strlen($sPhone) == 7){
    	$sPrefix = substr($sPhone,0,3);
	    $sNumber = substr($sPhone,3,4);
	    $sPhone = $sPrefix."-".$sNumber;
	    return($sPhone);
	  }else if (strlen($sPhone) == 6){
    	$sPrefix  = substr($sPhone,0,3);
	    $sNumber = substr($sPhone,3,3);
	    $sPhone = $sPrefix."-".$sNumber;
	    return($sPhone);
	  }else{
	  	return;
	  }
}

/* vim: set expandtab: */

?>
